package com.panshi.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.panshi.entity.SysRoleT;
import com.panshi.service.impl.SysRoleTServiceImpl;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 角色表 前端控制器
 * </p>
 *
 * @author xhlMr
 * @since 2020-08-13
 */
@RestController
public class SysRoleTController {

    @Autowired
    private SysRoleTServiceImpl sysRoleTService;

    @ApiOperation("角色关联表角色ID 查询角色信息")
    @GetMapping("/sys-role-t/getRole/{roleId}")
    public SysRoleT getRole(@PathVariable int roleId){
        return sysRoleTService.getById(roleId);
    }


    @ApiOperation("查询全部角色")
    @GetMapping("/sys-role-t/roleAll")
    public List<SysRoleT> roleAll(){
        return sysRoleTService.list(null);
    }


    @ApiOperation("按用户名查询  加分页")
    @GetMapping("/sys-role-t/rolelimit/{rolename}/{page}/{limit}")
    public List<SysRoleT> rolelimit(@PathVariable String rolename, @PathVariable int page, @PathVariable int limit){
        System.out.println(rolename+" ");
        if(page<1){
            page=1;
        }
        // 查询这个分类下的所有问题，获取查询的数据信息
        Page<SysRoleT> pageParam = new Page<>(page, limit);
        QueryWrapper<SysRoleT> wrapper = new QueryWrapper<>();

        if(rolename!=null&& !rolename.equals("-1")){//昵称查询
            wrapper.like("role_name",rolename);
        }
        sysRoleTService.page(pageParam,wrapper);

        List<SysRoleT> userPageAll = pageParam.getRecords();
        return userPageAll;
    }

}

